CREATE TABLE [dbo].[DnnProduct_UserPortals]
(
[UserId] [int] NOT NULL,
[PortalId] [int] NOT NULL,
[UserPortalId] [int] NOT NULL IDENTITY(1, 1),
[CreatedDate] [datetime] NOT NULL CONSTRAINT [DF_DnnProduct_UserPortals_CreatedDate] DEFAULT (getdate()),
[Authorised] [bit] NOT NULL CONSTRAINT [DF_DnnProduct_UserPortals_Authorised] DEFAULT ((1)),
[IsDeleted] [bit] NOT NULL CONSTRAINT [DF_DnnProduct_UserPortals_IsDeleted] DEFAULT ((0)),
[RefreshRoles] [bit] NOT NULL CONSTRAINT [DF_DnnProduct_UserPortals_RefreshRoles] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_UserPortals] ADD CONSTRAINT [PK_DnnProduct_UserPortals] PRIMARY KEY CLUSTERED  ([UserId], [PortalId]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_UserPortals] ON [dbo].[DnnProduct_UserPortals] ([PortalId]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_UserPortals_PortalId_IsDeleted] ON [dbo].[DnnProduct_UserPortals] ([PortalId], [IsDeleted]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_UserPortals] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_UserPortals_DnnProduct_Portals] FOREIGN KEY ([PortalId]) REFERENCES [dbo].[DnnProduct_Portals] ([PortalID]) ON DELETE CASCADE NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[DnnProduct_UserPortals] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_UserPortals_DnnProduct_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[DnnProduct_Users] ([UserID]) ON DELETE CASCADE NOT FOR REPLICATION
GO
